﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Green.FastInvoker
{
    public class CustomTypeDescriptorHelper
    {
        public static PropertyDescriptor GePropertyDescriptor(object obj, string propertyName)
        {
            var customTypeDescriptor = (obj as ICustomTypeDescriptor);
            if (customTypeDescriptor != null)
            {
                var propertyDescriptors = customTypeDescriptor.GetProperties();
                var property = propertyDescriptors.Find(propertyName, true);
                return property;
            }
            return null;
        }

        public static ICustomTypeDescriptor GetCustomTypeDescripties(object obj, string propertyName)
        {
            var customTypeDescriptor = (obj as ICustomTypeDescriptor);
            return customTypeDescriptor;
        }

        public static PropertyDescriptorCollection GePropertyDescriptors(object obj)
        {
            var customTypeDescriptor = (obj as ICustomTypeDescriptor);
            if (customTypeDescriptor != null)
                return customTypeDescriptor.GetProperties();
            return null;
        }

        public static bool IsCustomTypeDescriptor(object obj)
        {
            return (obj as ICustomTypeDescriptor) != null;
        }
    }
}
